package com.dandan.mobilelover.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dandan.mobilelover.component.Pagination;
import com.dandan.mobilelover.entity.Book;
import com.dandan.mobilelover.service.BookService;

@Controller
public class BookManageController {
	@Inject
	private BookService bookService;
	
	@Inject
	private Pagination page;
	
	@RequestMapping(value="/data_mgr/import_book", method= RequestMethod.GET)
	public String book_import(Model model){
		page.setTotalCount(35);
		page.setCurrentPage(2);
		List<Book> books = bookService.searchList(page);
		model.addAttribute("books", books);
		model.addAttribute("page", page);
		return "data_import/book_import";
	}
	
	
	@RequestMapping(value="/data_mgr/import_book/create", method=RequestMethod.POST)
	public String create_book(Book book,  Model model){
		bookService.saveBook(book);
		return "data_import/book_import";
	}
}
